package week_three_day03.dom;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class DomDemo04 {
	public static void main(String[] args) throws Exception{
		Document doc = new SAXBuilder(false).build(new FileInputStream("books.xml"));
		Element root = doc.getRootElement();
		System.out.println("root:"+root.getName());
		List<Element> cs = root.getChildren();
		ArrayList<Book> bookList = new ArrayList<Book>();
		for(Element c:cs){
			Book book = new Book();
			String Type = c.getAttributeValue("Type");
			String ISBN = c.getAttributeValue("ISBN");
			String title = c.getChild("title").getText();
			String author = c.getChild("author").getText();
			String price = c.getChild("price").getTextTrim();
			book.setTitle(title);
			book.setAuthor(author);
			book.setPrice(Double.parseDouble(price));
			book.setTyPe(ISBN);
			book.setISbN(ISBN);
			bookList.add(book);
			System.out.println(book);
		}
		System.out.println(bookList.size());
	}
}
